using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using pos.entity;
using System.Runtime.InteropServices;
namespace pos
{
    

   
  
    public partial class PayFrmConfirm : Form
    {
        [DllImport("kernel32.dll")]
        public static extern int WinExec(string exeName, int operType);
        public PayFrmConfirm()
        {
            InitializeComponent();
        }
        private double m_sumMoney;
        public double sumMoney
        {
            set
            {
                m_sumMoney = value;
            }
        }
        public double payMoney
        {
            get
            {
                return Convert.ToDouble(ss.Text);
            }
        }

        private void PayFrmConfirm_Load(object sender, EventArgs e)
        {
            ys.Text = m_sumMoney.ToString();

        }
        private bool checkSubmit()
        {
            if (ss.Text == "")
                return false;
            try
            {
                double payMoney = Convert.ToDouble(ss.Text);
                if (payMoney > 10000)
                    return false;
                if (zl.Text == "")
                {
                    double c = payMoney - m_sumMoney; ;
                    zl.Text = string.Format("{0:F2}", c);
                    return false;
                }

                string changeMoneystr =( payMoney - m_sumMoney).ToString("0.00"); 
                double changeMoney = Convert.ToDouble(zl.Text);
                //if ((long)((changeMoney1 + 0.00001) * 1000) != (long)((changeMoney + 0.00001) * 1000))
                if(changeMoneystr.CompareTo(zl.Text)!=0)
                {
                    double c = payMoney - m_sumMoney; ;
                    zl.Text = string.Format("{0:F2}", c);
                    return false;
                }
                if (changeMoney < 0)
                    return false;
                else
                    return true;

               
            }
            catch
            {
                return false;
            }
        }
        private void ss_KeyPress(object sender, KeyPressEventArgs e)
        {

            if (e.KeyChar == (char)Keys.O)
            {
             //   WinExec("C:\\Program Files\\Internet Explorer\\iexplore.exe   file://F:\\eclispse_work\\projects\\taobao_test\\test.htm?money=100", 5);
              //  return;
            }
            if (e.KeyChar == (char)Keys.Enter)
            {
                if (checkSubmit())
                    submit();
            }

        }
        private void submit()
        {
            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void cmdOK_Click(object sender, EventArgs e)
        {

            if (checkSubmit())
                submit();
            else
            {
                ss.SelectAll();
                
            }

        }

        private void ss_TextChanged(object sender, EventArgs e)
        {
            
            string str = ss.Text;
            if (str.Length == 0)
                return;

            string tmp=str.Substring(str.Length - 1);
            System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^[0-9\.]");
            int last = str.IndexOf('.');
            
            if (rex.IsMatch(tmp)&&(last >= 0?( str.IndexOf('.') == last && last + 4 > str.Length):true))
            {
                
                    
            }
            else
            {
                ss.Text=str.Substring(0, str.Length - 1);
                ss.SelectionLength = 0;
                ss.SelectionStart = ss.Text.Length;
                
            }

        }

    }
}